package com.blb.zy_community.mapper;

import com.blb.zy_community.entity.SysArea;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blb.zy_community.entity.SysDept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * 区域表 Mapper 接口
 * </p>
 *
 * @author 二组
 * @since 2023-06-18
 */
@Mapper
public interface SysAreaMapper extends BaseMapper<SysArea> {
    /**
     * 城市三级树形图查询
     * @return
     */
    @Results(id = "selectAreaMap",
            value = {
                    @Result(property = "id", column = "id", id = true),
                    @Result(property = "code", column = "code"),
                    @Result(property = "name", column = "name"),
                    @Result(property = "parentId", column = "parentId"),
                    @Result(property = "level", column = "level"),
                    @Result(property = "type", column = "type"),
                    @Result(property = "servicestate", column = "servicestate"),
                    @Result(property = "deleteFlag", column = "delete_flag"),
                    @Result(property = "region", column = "region"),
                    @Result(property = "childArea", column = "code", javaType = List.class,
                            many = @Many(select = "com.blb.zy_community.mapper.SysAreaMapper.selectChildAreaTreeByParentId"))
            })
    @Select("select * from sys_area where parentId = #{parentId}")
    List<SysArea> selectChildAreaTreeByParentId(Long parentId);
}
